package com.a214.yxz.yuejian013.Adapter;
import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.a214.yxz.yuejian013.Activity.ActivityDetailActivity;
import com.a214.yxz.yuejian013.JavaBean.Activitys;
import com.a214.yxz.yuejian013.R;
import com.squareup.picasso.Picasso;

import java.util.List;
/**
 * Created by hp-pc on 2017/10/13.
 */

public class ActivityAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{

    private Context mContext;//承载上下文
    private List<Activitys> mDataList;//动态数组承载数据使用
    private LayoutInflater mLayoutInflater;

    public ActivityAdapter(Context mContext,List<Activitys> mDataList){
        this.mContext=mContext;
        this.mDataList=mDataList;
        mLayoutInflater=LayoutInflater.from(mContext);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v=mLayoutInflater.from(parent.getContext()).inflate(R.layout.club,parent,false);
        return new ActivityAdapter.ViewHolder(v);

    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final Activitys entity=mDataList.get(position);
        if (null==entity)
            return;
        ActivityAdapter.ViewHolder viewHolder= (ActivityAdapter.ViewHolder) holder;
        viewHolder.name.setText(entity.getCity_name());
//        viewHolder.clubname.setText(entity.getClub_name());
        if(!entity.getThumb().isEmpty())
        {
            Picasso.with(mContext).load("http://172.24.10.175/workout/Uploads/"+entity.getThumb()).into(viewHolder.img);
        }
        else
        {
            viewHolder.img.setImageResource(R.drawable.ic_person);
        }

        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent  = new Intent (mContext, ActivityDetailActivity.class);
                //Bundle bundle = new Bundle();
                intent.putExtra("id",entity.getId());
                mContext.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return  mDataList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder{
        ImageView img;
        TextView name;
        //        TextView clubname;
        public ViewHolder(View itemView) {
            super(itemView);
            img= (ImageView) itemView.findViewById(R.id.club_pic);
            name= (TextView) itemView.findViewById(R.id.club_name);
//            clubname= (TextView) itemView.findViewById(R.id.name);
        }
    }

}